﻿Public Class Frm_Rech_Dossier_Orig

    Private Sub Frm_Rech_Dossier_Orig_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Frm_Dossier_Orig.Enabled = True
    End Sub

    Private Sub Frm_Rech_Dossier_Orig_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        comb_matorido_elbaht.SelectedIndex = 0
        txt_marji3ona.Text = Frm_Dossier_Orig.dv.Num
    End Sub

    Private Sub txt_rech_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_rech.TextChanged
        Try
            List_tous.Items.Clear()
            Partager.list_recherch.Clear()
            If comb_matorido_elbaht.SelectedItem = "رقم الملف الاصل" Then

                For Each av As fichier_origin In Frm_Dossier_Orig.dv.List_fichier_origine
                    If av.Num.ToString.Contains(txt_rech.Text) Then
                        Partager.list_recherch.Add(av)
                        List_tous.Items.Add(New ListViewItem(New String() {av.Num, av.Num_decision.ToString, av.date_decision.Date}))

                    End If

                Next


            ElseIf comb_matorido_elbaht.SelectedItem = "رقم الحكم أو القرار" Then

                For Each av As fichier_origin In Frm_Dossier_Orig.dv.List_fichier_origine
                    If av.Num_decision.ToString.Contains(txt_rech.Text) Then
                        Partager.list_recherch.Add(av)
                        List_tous.Items.Add(New ListViewItem(New String() {av.Num, av.Num_decision.ToString, av.date_decision.Date}))

                    End If

                Next

            ElseIf comb_matorido_elbaht.SelectedItem = "المقرر" Then

                For Each av As fichier_origin In Frm_Dossier_Orig.dv.List_fichier_origine
                    If av.mo9arir.ToString.Contains(txt_rech.Text) Then
                        Partager.list_recherch.Add(av)
                        List_tous.Items.Add(New ListViewItem(New String() {av.Num, av.Num_decision.ToString, av.date_decision.Date}))
                    End If

                Next


            ElseIf comb_matorido_elbaht.SelectedItem = "تاريخ الحكم أو القرار" Then

                For Each av As fichier_origin In Frm_Dossier_Orig.dv.List_fichier_origine
                    If av.date_decision.ToString.Contains(txt_rech.Text) Then
                        Partager.list_recherch.Add(av)
                        List_tous.Items.Add(New ListViewItem(New String() {av.Num, av.Num_decision.ToString, av.date_decision.Date}))
                    End If

                Next
            End If
            If txt_rech.Text = "" Then
                List_tous.Items.Clear()
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub Btn_choisi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_choisi.Click

        If List_tous.SelectedIndices.Count > 0 Then
            Dim j As Integer = 0
            Dim avo As fichier_origin
            Try
                For Each i As Integer In List_tous.SelectedIndices
                    avo = Partager.list_recherch.Item(i)
                    For Each khib As fichier_origin In Frm_Dossier_Orig.dv.List_fichier_origine
                        If avo.Id = khib.Id Then
                            Frm_Dossier_Orig.List_tous.Items(j).Focused = True
                            Frm_Dossier_Orig.List_tous.Items(j).Selected = True
                        End If
                        j += 1
                    Next
                Next
                Me.Close()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        Else
            MsgBox("اختر اجراء من القائمة", MsgBoxStyle.Information, "خطأ في البحث")
        End If
    End Sub
End Class